﻿using HungryCrowdLibrary.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using HungryCrowdLibrary;

namespace HungryCrowdLibrary.Manager
{
    public class MarketManager
    {
        internal MarketData marketData;
        internal MarketData MarketData { get { return marketData = marketData ?? new MarketData(); } }

        public bool SaveChanges(Market market)
        {
            var success = false;
            using (var hctx = new HungryCrowdEntities())
            {
                hctx.Markets.Add(market);
                success = hctx.SaveChanges() > 0;
            }
            return success;
        }


        public List<Market> GetList(Expression<Func<Market, bool>> search)
        {
            var markets = new List<Market>();
            using (var hctx = new HungryCrowdEntities())
            {
                markets = hctx.Markets.Include("Location").Where(search).ToList();
            }
            return markets;
        }

        #region Custom ORM Methods
        //public List<Market> GetList(int locationId)
        //{
        //    return MarketData.GetList(locationId);
        //}

        //public Market GetDetail(int marketId)
        //{
        //    return MarketData.GetDetail(marketId);
        //}
        #endregion

    }
}
